import {
  ADD_ONE,
  USER_LOGIN_SUCCESS,
  USER_LOGIN_FAILED,
  USER_LOGIN_REQUEST,
  FETCH_REQUEST
} from "../constants/actionTypes";

const initialState = {
  init: 1,
  data: {}
};

function userReducer(state = initialState, action) {
  switch (action.type) {
    case ADD_ONE:
      return {
        ...state,
        init: state.init + action.payload.num
      };
    case FETCH_REQUEST:
      return {
        ...state
      };
    case USER_LOGIN_SUCCESS: // 请求成功action
      console.log(action);
      return {
        ...state,
        data: action.payload.data.data
      };
    case USER_LOGIN_REQUEST: // 请求action
      return {
        ...state
      };
    case USER_LOGIN_FAILED:
      return {
        ...state
      };
    default:
      return state;
  }
}

export { userReducer };
